<?php
/**************************
@Author  : sulwan
@Content : 数据验证页面
**************************/
include_once(dirname(__file__).'/../../init.php');

$action = trim(_g('action'));
switch($action) {
case countWord:
	countWord();
	break;
case returnData:
	returnData();
	break;
case userName:
	userName();
	break;
case email:
	email();
	break;
case ename:
	ename();
	break;
default:
	showIndex();
}

/*默认执行方法*/
function showIndex() {
	$url = './index.php';
	$time = 2;
	$msg = '进入管理界面';
	redirect($url,$time,$msg);
}

/*统计字数*/
function countWord() {
	$word = trim(_g('word'));
	$number = mb_strlen($word);
	echo $number;
}

/*返回数据*/
function returnData() {
	$data = trim(_g('content'));
	echo $data;
}

/*检查用户名是否可以注册*/
function userName() {
	global $config;
	$userName = trim(_g('userName'));
	$usernameStr = strlen($userName);
	$res = array();
	$res = array('status'=>'','value'=>'');
	if ( $usernameStr<4||$usernameStr>15 ){
		$res['value'] = '用户名长度不对';
		echo json_encode($res);
		exit;
    }
	if ( !User::checkUserName($userName) ){
		$res['value'] = '请换一个用户名';
		echo json_encode($res);
		exit;
    }
	$res['status'] = 'Success';
	echo json_encode($res);
	exit;
}

/*检查邮箱是否可以注册*/
function email() {
	global $config;
	$email = trim(_g('email'));
	$res = array();
	$res = array('status'=>'','value'=>'');
	if ( !User::checkUserEmail($email) ){
		$res['value'] = '请换个邮箱';
		echo json_encode($res);
		exit;
	}
	$res['status'] = 'Success';
	echo json_encode($res);
	exit;
}

/*检查ename是否可以使用*/
function ename() {
	global $config;
	$ename = trim(_g('ename'));
	$res = array();
	$res = array('status'=>'','value'=>'');
	if ( !Article::checkEname($ename) ){
		$res['value'] = '请更换目录名';
		echo json_encode($res);
		exit;
	}
	$res['status'] = 'Success';
	echo json_encode($res);
	exit;
}
?>